package com.srabbit.betafan.util;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

import android.util.Base64;

public class HMACSHA1 {
	private static final String HMAC_SHA1 = "HmacSHA1";
	
	public static String encode(String s, String secret) throws Exception{
		byte[] data = s.getBytes("UTF-8");
		byte[] key = secret.getBytes("UTF-8");
		
		SecretKeySpec signingKey = new SecretKeySpec(key, HMAC_SHA1);  
        Mac mac = Mac.getInstance(HMAC_SHA1);  
        mac.init(signingKey);  
        byte[] rawHmac = mac.doFinal(data);
        
        return android.util.Base64.encodeToString(rawHmac, Base64.DEFAULT);
	}
	
}
